package com.ruoyi.common.storae.nfs;

import com.emc.ecs.nfsclient.nfs.io.Nfs3File;
import com.emc.ecs.nfsclient.nfs.io.NfsFileOutputStream;
import com.emc.ecs.nfsclient.nfs.nfs3.Nfs3;
import com.emc.ecs.nfsclient.rpc.CredentialUnix;

import java.io.*;

/**
 * Refs: https://raw.githubusercontent.com/EMCECS/nfs-client-java/master/src/test/java/com/emc/ecs/nfsclient/nfs/io/Test_Nfs3File.java
 */
public class NFSTransfer {

    private String ip = "114.55.58.148";
    private String dir = "/home/admin/ArcusNFS";

    public void tryConnect() throws IOException {
        Nfs3 nfs3 = new Nfs3(ip, dir, new CredentialUnix(0, 0, null), 3);
        Nfs3File nfs3File = new Nfs3File(nfs3, "/test.txt");

        File local = new File("/home/tacom/Development/Mounts/Project/arcus/seg_middleware/RuoYi-Vue/doc/nfs配置.md");
        BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(local));
        BufferedOutputStream outputStream = new BufferedOutputStream(new NfsFileOutputStream(nfs3File));

        byte[] buffer = new byte[1024];
        while ((inputStream.read(buffer)) != -1){
            outputStream.write(buffer);
        }
    }
}
